package com.ap.core.domain;

import com.ap.core.common.types.MerchantCtgyCode;
import com.ap.core.cxf.jaxb.common.ActivationStatus;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.annotations.TypeDef;

import javax.persistence.*;
import java.io.InputStream;
import java.sql.Blob;

/**
 * Entity class for Merchant
 */
@Entity
@Table(name = "T_MERCHANT")
@AttributeOverride(name = "id",column = @Column(name = "MERCHANT_ID"))
@TypeDef(name = "id", typeClass = Long.class)
public class Merchant extends Identifiable<Long> {

	private static final long serialVersionUID = -8014284968814978277L;

	@Column(name = "MERCHANT_IDENTIFICATION")
    private String merchantIdentification;

    @Column(name = "MERCHANT_GROUP_ID")
    private String merchantGroupId;

    @Column(name = "MERCHANT_NAME")
    private String name;

    @Column(name = "COMMON_NAME")
    private String commonName;

    @Column(name = "ACTIVATION_STATUS_CODE")
    @Enumerated(EnumType.STRING)
    private ActivationStatus activationStatus;

    @Column(name = "MERCHANT_CATEGORY_CODE")
    private String merchantCtgyCode;

    @Column(name = "ADDRESS_ID")
    private Long addressId;

    @Embedded
    @AttributeOverride(name = "accountNumber", column = @Column(name = "CREDIT_ACCOUNT_NUMBER"))
    private AccountNumber creditAccountNumber;

    @Embedded
    @AttributeOverride(name = "sortCode", column = @Column(name = "CREDIT_SORT_CODE"))
    private SortCode creditSortCode;

    @Embedded
    @AttributeOverride(name = "rollNumber", column = @Column(name = "CREDIT_ROLL_NUMBER"))
    private RollNumber creditRollNumber;

    @Column(name = "DISTRIBUTOR_ID")
    private Long distributorId;

    @Column(name = "UPDATE_REASON")
    private String updateReason;

    @Column(name = "MSG_ID")
    private Long apMessageId;

    @Column(name = "MERCHANT_LOGO")
    @Lob
    private Blob merchantLogo;
    

    private Merchant(){}

    public Merchant(Long addressId, Long apMessageId, String merchantIdentification, String commonName, String name, AccountNumber creditAccountNumber,
                    SortCode creditSortCode, Long distributorId, String merchantCtgyCode, ActivationStatus activationStatus) {
        this.addressId = addressId;
        this.apMessageId = apMessageId;
        this.merchantIdentification = merchantIdentification;
        this.commonName = commonName;
        this.name = name;
        this.creditAccountNumber = creditAccountNumber;
        this.creditSortCode = creditSortCode;
        this.distributorId = distributorId;
        this.merchantCtgyCode = merchantCtgyCode;
        this.activationStatus = activationStatus;
    }

    public void setCreditRollNumber(RollNumber creditRollNumber) {
        this.creditRollNumber = creditRollNumber;
    }

    public void setUpdateReason(String updateReason) {
        this.updateReason = updateReason;
    }

    public void setMerchantGroupId(String merchantGroupId) {
        this.merchantGroupId = merchantGroupId;
    }

    public void setMerchantLogo(InputStream inputStream, long length, Session session) {
        this.merchantLogo = Hibernate.getLobCreator(session).createBlob(inputStream, length);
    }

    public Blob getMerchantLogo() {
        return merchantLogo;
    }

    public Long getAddressId() {
        return addressId;
    }

    public Long getApMessageId() {
        return apMessageId;
    }

    public String getCommonName() {
        return commonName;
    }

    public AccountNumber getCreditAccountNumber() {
        return creditAccountNumber;
    }

    public RollNumber getCreditRollNumber() {
        return creditRollNumber;
    }

    public SortCode getCreditSortCode() {
        return creditSortCode;
    }

    public Long getDistributorId() {
        return distributorId;
    }

    public String getMerchantCtgyCode() {
        return merchantCtgyCode;
    }

    public String getMerchantGroupId() {
        return merchantGroupId;
    }

    public String getMerchantIdentification() {
        return merchantIdentification;
    }

    public String getName() {
        return name;
    }

    public ActivationStatus getActivationStatus() {
        return activationStatus;
    }

    public String getUpdateReason() {
        return updateReason;
    }

	public void setMerchantIdentification(String merchantIdentification) {
		this.merchantIdentification = merchantIdentification;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setCommonName(String commonName) {
		this.commonName = commonName;
	}

	public void setActivationStatus(ActivationStatus activationStatus) {
		this.activationStatus = activationStatus;
	}

	public void setMerchantCtgyCode(String merchantCtgyCode) {
		this.merchantCtgyCode = merchantCtgyCode;
	}

	public void setAddressId(Long addressId) {
		this.addressId = addressId;
	}

	public void setCreditAccountNumber(AccountNumber creditAccountNumber) {
		this.creditAccountNumber = creditAccountNumber;
	}

	public void setCreditSortCode(SortCode creditSortCode) {
		this.creditSortCode = creditSortCode;
	}

	public void setDistributorId(Long distributorId) {
		this.distributorId = distributorId;
	}

	public void setApMessageId(Long apMessageId) {
		this.apMessageId = apMessageId;
	}

	public void setMerchantLogo(Blob merchantLogo) {
		this.merchantLogo = merchantLogo;
	}
    
    
}